/*******家用空调国内电控物联网组*************/
//说明：净化器\除湿机\加湿器协议组包及解释库
//参考：智能终端及底板程序改编
//日期：2014-10-27
//作者：家用空调国内电控物联网组
//20141120001：加湿器模式返回位置调整，调整到byte no8 bit4-bit7
//20141120002：加湿器水箱提示方式调整，0:缺水；1-99:当前水箱水位百份比；100:水满 byte no10 bit0-bit6
//20150116003: 增除湿器干鞋模式
//20150116004: 增加上下摇摆(upanddownSwing)，左右摇摆控制(leftandrightSwing)，组包数据:byte no 10 bit4-bit3;解释数据:byte no 19 bit5-bit4


/********************************************/
package com.example.mideaoem.data;

import android.util.Log;


public  class fcCon {
	
	public static byte DEHUMI = (byte) 0xA1;//除湿机
	public static String DEHUMI_STR = "0xA1";

	public static byte HUMI = (byte) 0xFD;//加湿器
	public static String HUMI_STR = "0xFD";
	
	public static int DeviceType;
	public static final int DF = 0;
	public static final int DG = 1;
	public static final int TEST = 2;
	
	public static int mOrder = 0;
//	public static int mWindSpeed;

	public static int timerType = 0;// 0-无效 1-定时开 2-定时关
	public static int minutes_off = 0;// 目标时间 关机
	public static int minutes_on = 0;// 定时开机
	public static int minutes_reference;// 相对时间
	public static int humity;

	public static int ionSet;// 除湿器 负离子
	
	/*		协议类型		*/
	public final static int	PROTYPE_INVALID = 0; // 无效的
	public final static int	PROTYPE_LOWCOST = 1; // 低成本
	public final static int	PROTYPE_SMARTAN = 2; // 智能空调
	public final static int PROTYPE_VANDELO = 3; // 净化器 
	
/*		命令类型		*/
	public final static int	CMDTYPE_INVALID_CMD			= 0; // 无效指令

	// 低成本控制指令
	public final static int	CMDTYPE_QUERY_INFO 			= 1; // 查询设备当前状态信息    [结构定义见 curInfoQuery_Ex_t，返回结构见 stQueryInfoRes_Ex_t]
	
	public final static int CMDTYPE_QUERY_ONLINE_STATUS = 2; // 查询当前的设备在线状态  [结构定义见 NULL，返回结构见 stQueryOnlineInfoRes_Ex_t]
	public final static int CMDTYPE_SET   				= 4; // 修改、设置设备运行状态  [结构定义见 stSetInfo_Ex_t，返回结构见 stQueryInfoRes_Ex_t]

	public final static int CMDTYPE_GET_TYPEINFO        =24; // 获取家电信息            [结构定义见 airConBaseInfoReq_Ex_t，返回结构见 airConBaseInfoAck_Ex_t]

	/*		净化器模式类别		*/
	public final static int MODETYPE_FC_AUTO	= 1; // 自动模式
	public final static int MODETYPE_FC_MANU	= 2; // 手动模式
	public final static int MODE = 3;//SHUIMIAN 
	
	/*		除湿器模式类别		*/
	public final static int MODETYPE_A1_SET		= 1; // 设置模式
	public final static int MODETYPE_A1_CONT	= 2; // 连续模式
	public final static int MODETYPE_A1_AUTO	= 3; // 自动模式
	public final static int MODETYPE_A1_DRY		= 4; // 干燥模式
	public final static int MODETYPE_A1_SDRY    = 5; // 干鞋模式
	
	/*		加湿器模式类别		*/
	public final static int MODETYPE_FD_na		= 0; // 无效模式
	public final static int MODETYPE_FD_SET		= 1; // 手动模式
	public final static int MODETYPE_FD_CONT	= 2; // 自动模式
//	public final static int MODETYPE_FD_AUTO	= 3; // 手动模式
//	public final static int MODETYPE_FD_DRY		= 4; // 手动模式
	
	
	/*		风速枚举定义		*/
	public final static int WINDSPEED_LOW	= 1; // 1-低风
	public final static int WINDSPEED_MID	= 2; // 2-中风
	public final static int WINDSPEED_HIGH	= 3; // 3-高风
	public final static int WINDSPEED_STROG	= 4; // 4-强劲
	public final static int WINDSPEED_MUTE	= 5; // 5-静音风
	public final static int WINDSPEED_AUTO	= 6; // 6-自动风
	public final static int WINDSPEED_FIXED	= 7; // 7-固定风
	

	
	/*  信息获取  */
	public final int devID[] = new int[32];	// Device ID
	public final int snCode[]= new int[32];   // 家电SN
	public byte order;        // 帧序号
	public int sound;        // 提示音 0关 1开
	public int rev[] = new int[2];	

	/*  当前信息查询   */
	public int optCommand;	// 操作/控制命令
                                /*  0x00-同步信息指令
                                    0x01-随身感温度值   
                                    0x02-特殊功能键值
                                    0x03-查询状态
                                    0x04-安装位置检测
                                    0x05–工程模式
                                    0x06-制冷制热最大频率限制
                                    其他-无效指令
                                */



	public int returnsound;        // 提示音 0关 1开
	public int returnorder;        // 帧序号
	public int returnrev[] = new int[2];
	

/*  设备状态修改  */
	//public final static char order;            // 帧序号

	public int quickChkSts;		// 快检状态，0 - 关，1 - 开
	public int timingType;		// 0-相对定时，1-绝对定时
	public int iMode;				// i模式恢复，0 - 关，1 - 开
	public int runStatus;			// 开关控制，0-关，1-开	
	public int controlSource;		// 控制源，0-遥控器，1-移动终端
    public int childSleepMode;    // 儿童睡眠模式，0-关，1-开

	public int mode;				// 模式控制，见 modeType_Ex_em 定义
    public int timingIsValid; 	// 移动终端定时是否有效标记，0-无效，1-有效
	public int windSpeed;			// 风速控制 0-无效，1～100，固定风-101，自动风-102

	// 定时开机信息
	public int timingOnSwitch; 	// 定时开机是否开启，0-关闭，1-开启
	public int timingOnHour;		// 定时时间-小时
	public int timingOnMinute;	// 定时时间-分钟

	// 定时关机信息
	public int timingOffSwitch; 	// 定时关机是否开启，0-关闭，1-开启
	public int timingOffHour;		// 定时时间-小时
	public int timingOffMinute;	// 定时时间-分钟


	
	public int btnSound;			// 按键提示音控制，0-无提示，1-有提示	
	public int humidity;          //  0：无设定湿度 1：设定湿度1% 100，设定湿度100%
	
	/*****************净化器＋除湿器*****************************/
	public int mode_FC_return;	//净化器返回模式
	public int mode_F1_return;   //除湿机返回模式
	public int mode_FD_return;   //加湿器返回模式

	public int humidity_set_dot;	//设置湿度小数位
	
	public int humidity_cur;	 	//当前湿度整数位
	
	public int humidity_cur_dot;	 //当前湿度小数位
	public int filterShow;		 //滤网提示
	public int ionSetSwitch;		 //负离子开关
	public int sleepSwitch;       //舒睡开关
	public int pumpSwitch_flag;   //水泵控制是否有效椟 0:无效   1:有效
	public int pumpSwitch;		 //水泵控制  0:关   1:开
	public int displayClass;		 //屏显功能
	public int clearTime;         //清除风机运行时间
	public int dustTimeSet;		 //尘满提示时间设置 最小单位2小时
	public int dustTimeShow;		 //尘满提示时间提示	 最小单位2小时
	public int defrostingShow;    //化霜提示 0:关  1:开
	public int tankShow;    		 //水箱提示 0:未满 1:满
	public int rareShow;          //异味传感器 分0（好）-6（差）档
	public int dustShow;          //灰尘传感器 分0（好）-6（差）档
	public int pmLowValue;		 //PM2.5低8位
	public int pmHighValue;		 //PM2.5高8位
	public int rareValue;		 //异味传感器ad值
	public int indoorTmp;		 //室内温度（整数）表示方法：温度值 ＊ 2 ＋ 50
	public int indoorTmp_dot;	 //室内温度（小数）
	public int indoorTmpT1_dot;	 //T1温度（小数）
	public int lightClass;		 //光敏亮度等级
	public int lightValue;		 //光敏亮度ad值
	//public static int errCode;			 //故障代码

    public int upanddownSwing;		 //上下摇摆
    public int leftandrightSwing;	 //左右摇摆

	
 
    public int isUseDoubleTempCtrl;// 是否使用双温控制功能，0 - 非双温控制，1 - 双温控制
    public int isOpen8DegreeHot;  // 是否开启8度制热功能，0 - 关闭，1 - 开启

    public float tempSet;			// 温度控制，17.0℃-30.0℃
    public float tempSet2;			// 温度控制，13.0℃-35.0℃

    
    /*  状态查询及控制回复结构  */
	public int faultFlag;			// 故障标记，0-无故障，>0-有故障【高字节表示该故障是否影响运行，0为不影响，1为故障已停机；低字节表示故障代码，0为无故障】
    public int errCode;            // 故障代码
	public int rerunStatus;			// 运行状态，0 - 关机，1 - 开机
    public int requickChkSts;		// 快检状态，0 - 关，1 - 开
	public int reiMode;				// i模式恢复，0 - 关，1 - 开
	public int remode;				// 模式控制，见 modeType_Ex_em 定义
	public int rewindSpeed;			// 风速控制，0无效 1静音风; 2低风 3中风 4高风 5强劲风 6固定风 7自动风

	public int retimingType;		// 0-相对定时，1-绝对定时

	// 定时开机信息
	public int retimingOnSwitch; 	// 定时开机是否开启，0-关闭，1-开启
	public int retimingOnHour;		// 定时时间-小时
	public int retimingOnMinute;	// 定时时间-分钟

	// 定时关机信息
	public int retimingOffSwitch; 	// 定时关机是否开启，0-关闭，1-开启
	public int retimingOffHour;		// 定时时间-小时
	public int retimingOffMinute;	// 定时时间-分钟


	
	public int rehumidity;          //  0：无设定湿度 1：设定湿度1% 100，设定湿度100%

  
	
    public float		  tempIn;			// 室内温度
    public float		  tempOut;			// 室外温度
    public float		  retempSet;			// 设置温度
    public float		  retempSet2;			// 温度控制，13.0℃-35.0℃


    public float        retempRangeUpLimit;  // 温度上限值，13.0℃-35.0℃，双温控制时使用，tempSet或tempSet2作为下限值
    
/*
	public static float tempArray[][] = {
		{(float) 16.0, (float) 60.0},
        {(float) 16.5, (float) 61.0},
        {(float) 17.0, (float) 62.0},
        {(float) 17.5, (float) 63.0},
        {(float) 18.0, (float) 64.0},
        {(float) 18.5, (float) 65.0},
        {(float) 19.0, (float) 66.0},
        {(float) 19.5, (float) 67.0},
        {(float) 20.0, (float) 68.0},
        {(float) 20.5, (float) 69.0},
        {(float) 21.0, (float) 70.0},
        {(float) 21.5, (float) 71.0},
        {(float) 22.0, (float) 72.0},
        //{22.5, 73.0},
        {(float) 23.0, (float) 73.0},
        {(float) 23.5, (float) 74.0},
        {(float) 24.0, (float) 75.0},
        {(float) 24.5, (float) 76.0},
        {(float) 25.0, (float) 77.0},
        {(float) 25.5, (float) 78.0},
        {(float) 26.0, (float) 79.0},
        {(float) 26.5, (float) 80.0},
        {(float) 27.0, (float) 81.0},
        //{27.5, 82.0},
        {(float) 28.0, (float) 82.0},
        {(float) 28.5, (float) 83.0},
        {(float) 29.0, (float) 84.0},
        {(float) 29.5, (float) 85.0},
        {(float) 30.0, (float) 86.0},
        {(float) 30.5, (float) 87.0},
        {(float) 31.0, (float) 88.0},
        {(float) 31.5, (float) 89.0}};



//TP温度值表
	public static int[] TPValues ={
        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   2,   3,   5,   6,
        8,   9,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,
        24,  25,  26,  27,  27,  28,  29,  30,  30,  31,  32,  32,  33,  34,  34,  35,
        36,  36,  37,  37,  38,  39,  39,  40,  40,  41,  41,  42,  42,  43,  44,  44,
        45,  45,  46,  46,  47,  47,  48,  48,  49,  49,  50,  50,  51,  51,  52,  52,
        53,  53,  54,  54,  55,  55,  56,  56,  56,  57,  57,  58,  58,  59,  59,  60,
        60,  61,  61,  62,  62,  63,  63,  63,  64,  64,  65,  65,  66,  66,  67,  67,
        68,  68,  69,  69,  69,  70,  70,  71,  71,  72,  72,  73,  73,  74,  74,  75,
        75,  76,  76,  76,  77,  77,  78,  78,  79,  79,  80,  80,  81,  81,  82,  82,
        83,  83,  84,  84,  85,  85,  86,  86,  87,  87,  88,  88,  89,  90,  90,  91,
        91,  92,  92,  93,  93,  94,  95,  95,  96,  96,  97,  98,  98,  99,  99, 100,
        101, 101, 102, 103, 103, 104, 105, 105, 106, 107, 107, 108, 109, 109, 110, 111,
        112, 112, 113, 114, 115, 116, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
        126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 144, 145, 147, 148,
        150, 152, 153, 155, 157, 159, 161, 163, 165, 168, 170, 173, 175, 178, 181, 185,
        188, 192, 196, 201, 206, 211, 218, 225, 233, 243, 254, 255, 255, 255, 255, 255,};
*/	
	
	// CRC8校验数据表 X^8 + X^5 + X^4 + 1
	public static  int[] crc8_854_table =
	{
		0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
		157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
		35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
		190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
		70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
		219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
		101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
		248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
		140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205,
		17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80,
		175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238,
		50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
		202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
		87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
		233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
		116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53
	};	
	
	//unsigned char crc8_854( unsigned char *dataBuf, unsigned char dataLen )
	private static int crc8_854(int[] dataBuf, int dataLen )
	{
		int crc = 0;

		if ( null == dataBuf || 0 == dataLen )
		{
			return crc;
		}

		
		int[] tmp = dataBuf;

		int si = 0;
		for(si = 0; si< dataLen; si++)
		{
			try {
				int index = crc ^ (tmp[si]);
			if(index > 256){
				index -= 256;
			}
			if(index < 0){
				index += 256;
			}
			crc = crc8_854_table[index];
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		return crc;
	}
/*
	private int  makeSum(int[] dataBuf, int dataLen)
	{
	    int SumValue = 0;
	    int tmpCnt = 0;

	    while( tmpCnt < dataLen )
	    {
	        SumValue += dataBuf[tmpCnt++];
	        SumValue = SumValue % 0x100;
	    }

	    //取余
	    SumValue = 0xff - SumValue;
	    //加1
	    SumValue = SumValue + 1;

	    return SumValue;
	}
*/	
	
	/*
	private int BCDToInt(int i) {
		// TODO Auto-generated method stub
		return 0;
	}
	private float TempValCheck(int tempModeSwitch2, float tempSet3) {
		// TODO Auto-generated method stub
		return 0;
	}
	*/
	

	private static  int checkTempVal(float val) {
		// TODO Auto-generated method stub
	   return (int) ((val < 17.0) ? (17.0) : ((val > 30.0) ? (30.0) : (val)));
	}
	
	
	private  float TempValCheck(int tempMode, float tempVal)
	{
	    float resVal = (float) 0.0;
		int comVal = (int)(tempVal * 10 + 0.5);
	    
	    /*
	     ** tempMode=0为摄氏温度，=1为华氏温度
	     */
	    if (0 == tempMode)
	    {
	        resVal = (float) ((comVal < 170) ? (17.0) : ((comVal > 300) ? (30.0) : (tempVal)));
	    }

	    if (1 == tempMode)
	    {
	        resVal = (float) ((comVal < 600) ? (60.0) : ((comVal > 890) ? (89.0) : (tempVal)));
	    }

	    return resVal;
	}
	
	private  int BCDToInt(int bcd)
	{
	    return (0xf & (bcd>>4))*10 +(0xf & bcd);
	}	
	
    
	private static int makeSum(int tmpbuf[],int tmpLen)
	{
		int resVal = 0;
		int si;
		for(si = 1; si < tmpLen; si++)
		{
			resVal = resVal + tmpbuf[si];
		}
		resVal = (int)(255 -(resVal % 256)) + 1;
		
		return resVal;
		
	}

	// 解析函数,将接收到的数据进行解释，获得空调状态数据
	//*srcBuf:待解释数据（组）,即家电私有协议中的数据
	//srcLen:待解释数据（组）长度
	//*msgType:命令类型
	//*dstBuf:解释后数据（组）
	//*srcBuf:解释后数据（组）长度
	public int stdAirConEx_byte2pro(int[] srcBuf, int srcLen, int msgType, int[] dstBuf, int dstLen)
	{
//	    if ( (null == srcBuf) || (0 == srcLen) || (0 == msgType) || (null == dstBuf) || (0 == dstLen) || (0 == dstLen) )
//	    {
//	        msgType = CMDTYPE_INVALID_CMD;
//	        dstLen = 0;
//	        return -1;
//	    }
	    
//	    if ( 0xAA != srcBuf[0]) // head
//	    {
//			msgType = CMDTYPE_INVALID_CMD;
//			dstLen = 0;
//	        return -2;
//	    }
//
//	    int datLen = srcBuf[1]+1;
//
//	    if ( ( 2 > srcLen ) || (srcBuf[1]+1) > srcLen )
//	    {
//	        msgType = CMDTYPE_INVALID_CMD;
//	        dstLen = 0;
//	        return -3;
//	    }

	    int datLen = srcLen;
//		datLen = (datLen < 2) ? 2 : datLen;
	    //char crcRet= crc8_854(&srcBuf[10],srcBuf[1]-11);
//		char crcRet= (char) crc8_854(srcBuf,datLen-1);
		
//		if(crcRet!=srcBuf[datLen-1])
//		{
//			msgType = CMDTYPE_INVALID_CMD;
//			dstLen = 0;
//			return -5;
//		}
//	    int ckSum = makeSum(srcBuf, datLen-1);
//	    if (srcBuf[datLen-1] != ckSum)
//	    {
//			msgType = CMDTYPE_INVALID_CMD;
//			dstLen = 0;
//	        return -4;
//	    }

//		int typeMsg = srcBuf[9];
	    int msgcmd  = srcBuf[0];
	    // 控制or查询返回
	    if ( 0xC8 == msgcmd || 0xA0 == msgcmd || 0x48 == msgcmd)
	    {
			//char info[] = &srcBuf[10];
			//stQueryInfoRes_Ex_t tmp = {0};
	    	
	    	//char info[] = new char[64]; 
	    	int info[] = new int[64];
	    	
	    	System.arraycopy(srcBuf,0,info,0,srcLen);

			faultFlag = (info[1] & 0x80) >> 7;//(info[1] & 0x80) ? 1:0;
			runStatus = (info[1] & 0x01);//(info[1] & 0x01) ? 1:0;
			timingType = (info[1] & 0x10) >> 4;//(info[1] & 0x10) ? 1:0;
			iMode = (info[1] & 0x04) >> 2;//(info[1] & 0x04) ? 1:0;
			quickChkSts = (info[1] & 0x20) >> 5;//(info[1] & 0x20) ? 1:0;

			//mode = (info[2]&0xE0)>>5;
			//tempSet = (info[2]&0x0F)+16;
			mode_FC_return = (info[2] & 0xf0)>>4;
			mode_F1_return = info[2] & 0x0F;


	        windSpeed = info[3] & 0x7F;

	        timingOnSwitch = (info[4] & 0x80) >> 7;//(info[4] & 0x80) ? 1:0;//定时开机  
	        timingOffSwitch = (info[5] & 0x80) >> 7;//(info[5] & 0x80) ? 1:0;//定时开机  

	        if ( 1 == timingType )
	        {
	            if ( 1 == timingOnSwitch )
	            {
	                timingOnHour = ((info[4]&0x7F)>>2) & 0x1F;//绝对定时 小时
	                timingOnMinute =(((info[4]&0x7F)&0x03))*15+ ((info[6] & 0xF0));//绝对定时 分
	            }

	            if ( 1 == timingOffSwitch )
	            {
	                timingOffHour = ((info[5]&0x7F)>>2) & 0x1F;//绝对定时 小时
	                timingOffMinute =(((info[5]&0x7F)&0x03))*15 + ((info[6] & 0x0F));//绝对定时 分
	            }
	        }
	        // 相对时间
	        else    
	        {
	            if ( (1 == timingOnSwitch) && (0x7F != (info[4]&0x7F)) )
	            {
	                timingOnHour = ((((info[4]&0x7F)+1)*15) - ((info[6] >> 4)&0x0F))/60;
	                timingOnMinute = ((((info[4]&0x7F)+1)*15) - ((info[6] >> 4)&0x0F))%60;
	            }

	            if ( (1 == timingOffSwitch) && (0x7F != (info[5]&0x7F)) )
	            {
	                timingOffHour = ((((info[5]&0x7F)+1)*15) - (info[6]&0x0F))/60;
	                timingOffMinute = ((((info[5]&0x7F)+1)*15) - (info[6]&0x0F))%60;
	            }
	        }

	        humidity = info[7];
	        if(info[7] > 100) info[7] = 99;	    //设置湿度整数位
	        humidity_set_dot = info[8] & 0x0F;	//设置湿度小数位
	        //SAFGAHSJDK
	        mode_FD_return = (info[10] & 0x07);   //加湿器返回模式 20141120002	        

	        filterShow = (info[9] & 0x80)>>7;	//滤网提示

	        ionSetSwitch = (info[9] & 0x40)>>6;	//负离子开关

	        sleepSwitch = (info[9] & 0x20)>>5;  //舒睡开关

	        pumpSwitch_flag = (info[9] & 0x10)>>4;	//水泵控制是否有效  0:无效   1:有效

	        pumpSwitch= (info[9] & 0x08)>>3;	//水泵控制开关  0:关   1:开
	        
	        displayClass = (info[9] & 0x07);	//屏显功能

	        defrostingShow = (info[10]&0x80) >> 7;    //化霜提示 0:关  1:开

	        //tankShow = (info[10]&0x40) >> 6;    	//水箱提示 0:未满 ;100:满
	        tankShow = (info[10] & 0x7F);    	//水箱提示 0:未满 ;100:满 2014112001
	        
	        
	        dustTimeShow = info[11] * 2;	//尘满提示时间提示	最小单位2小时
	        
	        rareShow = (info[12]&0x38) >> 3;          //异味传感器 分0（好）-6（差）档

	        dustShow = (info[12]&0x07);          //灰尘传感器 分0（好）-6（差）档

	        pmLowValue = info[13];	//PM2.5低8位

	        pmHighValue  = info[14];	//PM2.5高8位

	        rareValue = info[15];	//异味传感器ad值
	        
	        humidity_cur = info[16];	//当前湿度值

	        Log.d("家电上报","解析前的湿度 = "+humidity_cur);
	        
	        indoorTmp = info[17];	//室内温度（整数）表示方法：温度值 ＊ 2 ＋ 50

	        //indoorTmp_dot = info[17] & 0xF0;	//室内温度（小数）
	        humidity_cur_dot = info[18] & 0xF0; //当前湿度小数位

	        indoorTmpT1_dot = (info[18] & 0x0F)>>4;	//T1温度（小数）

	        
	        lightClass = info[19] & 0xF0;	//光敏亮度等级

			upanddownSwing    = (info[19] & 0x20) >> 5;
			leftandrightSwing = (info[19] & 0x20) >> 4;

	        lightValue = info[20];	//光敏亮度ad值

	        errCode = info[21];	//故障代码	        
	         
	    }
	    else
	    {
	    	/*
	        *msgType = CMDTYPE_INVALID_CMD;
	        *dstLen = 0;
	        return -10;
	        */
	        msgType = CMDTYPE_INVALID_CMD;
	        return -10;
	    }

	    return 0;
	}

	// 组包函数
	//*msgType:命令类型
	//*srcBuf:待组包数据（组）,即家电私有协议中的数据
	//srcLen:待组包数据（组）长度
	//*dstBuf:组包后数据（组）
	//*srcBuf:组包后数据（组）长度

	public int stdAirConEx_pro2byte(int devType,int msgType, int srcBuf[], int srcLen, int dstBuf[], int dstLen)
	{
	    if ( (null == dstBuf) || (0 == dstLen) || (0 == dstLen) )
	    {
	        //*dstLen = 0;
	        return -1;
	    }
	    
	    int tmpBuf[] = new int[128];
	    
	    switch ( msgType )
	    {
	        case CMDTYPE_QUERY_INFO:
			{
				tmpBuf[0] = 0x41;
				tmpBuf[1] = ((sound << 6) | 0x21);
				tmpBuf[2] = 0x00;
				tmpBuf[3] = 0xFF;
				tmpBuf[4] = optCommand;//暂时只支持03
				tmpBuf[5] = 0x00; 
				tmpBuf[6] = 0x00;
				tmpBuf[7] = 0x02;
				
				tmpBuf[8] = 0x00;
				tmpBuf[9] = 0x00;
	            
				tmpBuf[10] = 0x00;
				tmpBuf[11] = 0x00;
				tmpBuf[12] = 0x00;
				tmpBuf[13] = 0x00;
				tmpBuf[14] = 0x00;
				tmpBuf[15] = 0x00;
				tmpBuf[16] = 0x00;
				tmpBuf[17] = 0x00;
				tmpBuf[18] = 0x00;
				tmpBuf[19] = 0x00;
				tmpBuf[20] = order;
				
				//tmpBuf[31] = crc8_854(&tmpBuf[10], 21);
				tmpBuf[21]= (int) crc8_854(tmpBuf,21);
				
				// Data Len
				//tmpBuf[1] = 32;
	            
				//tmpBuf[32] = makeSum(tmpBuf, tmpBuf[1]);//makeSum(&tmpBuf[1], 31);
	            
				dstLen = 22;
				System.arraycopy(tmpBuf,0,srcBuf,0,dstLen);
				
				return dstLen;
			}
//	            break;
	            
	        case CMDTYPE_SET:
			{

				tmpBuf[0] = 0x48;
	            
				tmpBuf[1] = (((btnSound & 0x01) << 6)
	            | ((quickChkSts & 0x01) << 5)
	            | ((timingType & 0x01) << 4)
	            | ((childSleepMode & 0x01) << 3)
	            | ((iMode & 0x01) << 2)
	            | ((controlSource & 0x01) << 1)
	            | ((runStatus & 0x01) << 0));
	            
				int u8Temp = 0;
				tmpBuf[2] = (((mode_FC_return & 0x0F) << 4) | (mode_F1_return & 0x0F));// | ((u8Temp - 16) & 0x0F);
	            
	            int tmpData = 0;
	            
				tmpBuf[3] = (((timingIsValid & 0x01) << 7) | (windSpeed & 0x7F));
	            
	            if ( 1 == timingType )
	            {
	                tmpBuf[4] = ((timingOnSwitch << 7)
	                | (timingOnHour << 2)
	                | (timingOnMinute / 15)) ;
	                
	                tmpBuf[5] = ((timingOffSwitch << 7)
	                | (timingOffHour << 2)
	                | (timingOffMinute & 0x03)) ;
	                
	                tmpBuf[6] = (((timingOnMinute %15) << 4) | ((timingOffMinute % 15) )) ;
	            }
	            else
	            {
	                // 定时开时间计算
	                int tmpMinute = timingOnHour*60+timingOnMinute;
	                
	                if ( (1 == timingOnSwitch) && (0 != tmpMinute) ) // 定时开开启
	                {
	                    tmpBuf[4] = 0x80;
	                    
	                    if ( 0 != (tmpMinute%15) )
	                    {
	                        tmpBuf[4] |= (tmpMinute / 15) & 0x7F;
	                        tmpBuf[6] |= ((15 - (tmpMinute % 15)) & 0x0F) << 4;
	                    }else
	                    {
	                        tmpBuf[4] |= ((tmpMinute / 15) - 1) & 0x7F;
	                        tmpBuf[6] &= 0x0F;
	                    }
	                }
	                else
	                {
	                	tmpBuf[4] = 0x7F;
	                    tmpBuf[6] &= 0x0F;
	                }
	                
	                // 定时关时间计算
	                tmpMinute = timingOffHour*60+timingOffMinute;
	                
	                if ( (1 == timingOffSwitch) && (0 != tmpMinute) )	// 定时关开启
	                {
	                    tmpBuf[5] = 0x80;
	                    
	                    if ( 0 != (tmpMinute%15) )
	                    {
	                        tmpBuf[5] |= (tmpMinute / 15) & 0x7F;
	                        tmpBuf[6] |= (15 - (tmpMinute % 15)) & 0x0F;
	                    }else
	                    {
	                        tmpBuf[5] |= ((tmpMinute / 15) - 1) & 0x7F;
	                        tmpBuf[6] &= 0xF0;
	                    }
	                }
	                else
	                {
	                	tmpBuf[5] = 0x7F;
	                    tmpBuf[6] &= 0xF0;
	                }
	            }
	            
	            tmpBuf[7] = humidity & 0x7F;			//设置湿度
	            tmpBuf[8] = humidity_set_dot & 0x0f;			//设置湿度小数
				 
				tmpBuf[9] = ((displayClass & 0x07)
	            | (pumpSwitch << 3)
	            | (pumpSwitch_flag << 4)
	            | (sleepSwitch << 5)
	            | (ionSetSwitch << 6)
	            | (filterShow << 7));
	            
				tmpBuf[10] = ((mode_FD_return & 0x07)
	            | (clearTime << 7));
	            
				tmpBuf[10] = tmpBuf[10] | (upanddownSwing << 3)| (leftandrightSwing << 4);

				tmpBuf[11] = dustTimeSet;	//尘满提示时间设置 最小单位2小时
				
				tmpBuf[12] = 0;	
				tmpBuf[13] = 0;	
				tmpBuf[14] = 0;	
				tmpBuf[15] = 0;	
				tmpBuf[16] = 0;	
				tmpBuf[17] = 0;	
				tmpBuf[18] = 0;	
				tmpBuf[19] = 0;	
				tmpBuf[20] = 0;	
				tmpBuf[21] = 0;	
				
				tmpBuf[22] = order;
	            
				//tmpBuf[33] = crc8_854(&tmpBuf[10], 23);
				tmpBuf[23]= (int) crc8_854(tmpBuf,23);
	                  

				dstLen = 24;
				System.arraycopy(tmpBuf,0,srcBuf,0,dstLen);	
				
				return dstLen;
			}
	        default:
	        {
	            return -2;
	        }
	    }
	}

	@Override
	public String toString() {
	// TODO Auto-generated method stub
//	return "加湿机Model "+"  开机状态  = "+runStatus+"  设置的湿度 = "+humidity+"  设置的湿度小数 = "+humidity_set_dot+
//			"  收到的湿度 = "+humidity_cur+"  收到的湿度小数 = "+humidity_cur_dot+ "风速 = "+windSpeed+
//			"  屏显 = "+displayClass+"  模式 = "+mode_FD_return+"  水箱 = "+tankShow+"  过滤网 = "+filterShow;
		
		
	return "除湿机Model "+"  水箱 = "+tankShow+"  摇摆 = "+upanddownSwing+"  负离子 = "+ionSetSwitch+"  开机状态 = "+runStatus+"  设置的湿度 = "+humidity+"  设置的湿度小数 = "+humidity_set_dot+
			"  收到的湿度 = "+humidity_cur+"  收到的湿度小数 = "+humidity_cur_dot+
			"  风速 = "+windSpeed+"  模式 = "+mode_F1_return+"  定时 = "+timingIsValid+
			"  定时开 = "+timingOnSwitch+"  定时开H = "+timingOnHour+"  定时开M = "+timingOnMinute+"  定时关 = "+timingOffSwitch+
			"  定时关H = "+timingOffHour+"  定时关M = "+timingOffMinute;
}
	
}
